app: extract the create backup usecase - #1205
huanghaoyuanhhy wants to merge 4 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: huanghaoyuanhhy The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (71.14%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1205 +/- ##
==========================================
+ Coverage 46.89% 47.80% +0.90%
==========================================
Files 140 141 +1
Lines 12845 12827 -18
==========================================
+ Hits 6024 6132 +108
+ Misses 6386 6255 -131
- Partials 435 440 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: huanghaoyuanhhy <haoyuan.huang@zilliz.com>
Signed-off-by: huanghaoyuanhhy <haoyuan.huang@zilliz.com>
The v1 backup_root_path field used to travel on the request and the usecase resolved it over the configured root path by hand. Apply it as one more override layer on the loaded config instead (zilliztech#1215): the handler forks, the usecase reads the root path from the params it was built with, and CreateBackupRequest loses its RootPath field. The fork is reload-equivalent, so unset backup.storage leaves still cascade from milvus.storage, and the server's own config is never mutated. Also drop the expectMetaSize copy the rebase onto zilliztech#1203's app/get_backup_test.go left duplicated in create_test.go. Signed-off-by: huanghaoyuanhhy <haoyuan.huang@zilliz.com>
dd88631 to
5f3b2eb
Compare
A create call makes a job; the backup artifact is what a successful job leaves behind, read through GetBackup. Execute now returns only the task manager's view of the job (the shape v2's jobs/backup/create responds with) and never reads the persisted meta. The v1 sync response keeps its code+msg-only shape; the old post-success meta read that could turn the response into Fail is gone with the discarded payload it fed. Signed-off-by: huanghaoyuanhhy <haoyuan.huang@zilliz.com>
Part of #1171
What
appgains theCreateBackupusecase: one struct holding the config, the two storage clients, the task manager and the backup root path, constructor-built from config. The action is create a backup job: a job is what a create call makes, and the backup artifact is what a successful job leaves behind — the two-resource split of the v2 API (#1124), wherejobs/backup/createreturns the job andbackups/describereads the artifact.Start(req)is the synchronous act of starting a job — it assemblesbackup.TaskArgsand callsbackup.NewTask, which registers the job in the task manager, and returns the registered job ready to run behind a smallBackupJobinterfaceExecute(ctx, req)runs the job synchronously and answers with the task manager's view of it: id, state, progress and the rest of the job half — the shape v2'sjobs/backup/createresponds with. It never reads the persisted meta; a transport whose contract merges the two resources (v1) assembles what it needs itselfBoth transports call it:
createCLI command (cmd/create) buildsapp.NewCreateBackup+Execute; flag parsing, name defaulting, validation and the printed output stay incmd/api/v1/createhandler (core/server) renders the pb request intoapp.CreateBackupRequest— keeping the deprecated pb fields (db_collections,collection_names,force,meta_only), name validation and the error-to-code mapping — through anewCreateBackupconstructor hook on the server config that tests stub out, the same seam list and delete got in app: extract the list backups usecase #1182 and app: extract the delete backup usecase #1200asyncflag stays a server concern: the handler callsStartand spawns the goroutine itself (unchanged logging on failure), while taskmgr registration stays where it was, insidebackup.NewTask.core/backupis not touchedNewCreateBackuptakes the task manager as a parameter instead of readingtaskmgr.DefaultMgr()itself;cmd/createand the server wiring pass the process-local manager, keeping the global reference out of the usecase layerRebased on top of the config fork (#1215): the v1
backup_root_pathfield is applied as a config override, not a request field. The handler forks the loaded config withbackup.storage.rootPathas one more override layer — the same moveget_backupmakes for itspathparameter in #1203 — and the forked params are whatNewCreateBackupbuilds the usecase from, soCreateBackupRequestcarries no root path and the usecase reads it from its params. The fork is reload-equivalent, so unsetbackup.storageleaves still cascade frommilvus.storage, and the server's own config is never mutated. The artifact directory for a given request is the same as before the rebase.Semantics unchanged
The v1 wire shape is kept, including its quirks:
codeandmsg— no payload and norequest_id. The usecase now answers with the job view alone, and the v1 contract needs nothing from it, so the handler discards it; anything a v1 response does need, the handler assembles itselfrequest_iddefaulting, error-to-code mapping (Parameter_Errorfor a bad name,Failfor everything else,request_idechoed on failures), filter/strategy/format precedence and the deprecated-field fallbacks are unchangedcreate backup is executing asynchronously), samerequest_idecho, task still registered synchronously in the default task manager before the goroutine startsTwo pre-existing bugs were found and are not fixed here:
backup_namestill panics inbackup.ValidateNameand lands on gin's recovery as a 500, exactly as beforeTwo deliberate behavioral deltas, both limited to error paths:
backup.NewTaskerror intotask.Executeon a nil task — a guaranteed panic. The usecase returns that error instead, so a job whose registration fails now answersFailwith the error messageFailwhen any of those reads failed — even though the backup had already succeeded — all to build a brief it then discarded. That read only ever fed the discarded payload, so it is gone together with the payload: a successful backup now always answers successTests
app/create_test.go:Startregisters the job in the task manager and refuses a second live job for the same backup name;Executepropagates the start failure; the artifact dir is the configured root path plus the option's namecore/server/create_test.go: httptest cases over the handler contract — sync runs through the usecase and the success response carries no payload (quirk pinned), request_id generated and forwarded, invalid name rejected withParameter_Errorbefore the usecase runs, constructor/build/execute/start errors mapped toFail, async starts the job and returns immediately,backup_root_pathforks the loaded config while the server's own config stays on the default root path (and without the field the config travels to the usecase untouched); plus the pb→option rendering incl. deprecatedforce/meta_onlyand the three filter sources